package com.ujiuye.web;

import com.ujiuye.enity.PageUtils;
import com.ujiuye.enity.Student;
import com.ujiuye.service.StuService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class QueryStuLikeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter pw = resp.getWriter();
        //获取页面发送过来的当前页参数
        String curPage = req.getParameter("curPage");
        //获取姓名，性别
        String name = req.getParameter("name");
        String sex = req.getParameter("sex");
        //调用模糊查询的方法
        StuService ss = new StuService();
        //获取模糊查询记录数
        int rows = ss.queryLikeNum(name,sex);
        PageUtils pu = new PageUtils(rows,curPage);
        List<Student> list = ss.queryStuLike(name,sex,pu);
        //绑定数据
        req.setAttribute("list",list);
        req.setAttribute("pu",pu);
        req.setAttribute("name",name);
        req.setAttribute("sex",sex);
        //转发
        req.getRequestDispatcher("show.jsp").forward(req,resp);
    }
}
